/*
qnettest - Qt4 application for testing network performance
Copyright (C) 2007  Pyry Haulos

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef TCPCLIENT_H
#define TCPCLIENT_H
#include "tcpclienthelper.hpp"

// #define TCPCLIENT_DEBUG

#include <QObject>
#include <QVector>
#include <QTcpSocket>

class QTextStream;
class QString;
class QTime;

struct TcpProtoTestData;
struct TcpClientArgs {
	QString address;
	quint16 port;
	qint32 simult_num;
	qint32 send_bytes;
	qint32 recv_bytes;
	qint32 time;
	qint32 interval;
	QTextStream *outStream;
};

class TcpClient:public QObject {
	Q_OBJECT

public:
	TcpClient(TcpClientArgs *args);
	~TcpClient();

	bool start();

signals:
	void finished();

public slots:
	void addHelperReport(qint32 packet_count);
	void helperFinished();

protected:
	void showReport();

	TcpClientArgs *args;
	TcpProtoTestData *testdata;

	qint32 active_helpers, helper_reports_i;
	qint32 *helper_reports;

	quint32 estimated_up_KBps, estimated_down_KBps;

	QVector <TcpClientHelper *> *helpers;

	QTime *time;
	
	QTextStream *out;
};

#endif // TCPCLIENT_H
